package cn.itsource.pethome.quartz.service.impl;

import cn.itsource.pethome.quartz.MainJob;
import cn.itsource.pethome.quartz.domain.QuartzJobInfo;
import cn.itsource.pethome.quartz.service.IQuartzService;
import cn.itsource.pethome.quartz.utils.QuartzUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService {
    @Autowired
    private SchedulerFactoryBean schedulerFactoryBean;

    /**
     * 添加定时任务
     * @param quartzJobInfo 定时任务需要的参数
     */
    @Override
    public void addJob(QuartzJobInfo quartzJobInfo) {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        QuartzUtils.addJob(scheduler, quartzJobInfo.getJobName(), MainJob.class, quartzJobInfo, quartzJobInfo.getCronj());
    }
}
